package com.ark.cloud.javacallnative.modules.storage.service.impl;

import com.ark.cloud.javacallnative.entity.Vec3D;
import com.ark.cloud.javacallnative.entity.WaypointCmd;
import com.ark.cloud.javacallnative.entity.WaypointCmdVecThreed;

import com.ark.cloud.javacallnative.modules.storage.mapper.Vec3DMapper;
import com.ark.cloud.javacallnative.modules.storage.mapper.WaypointCmdMapper;
import com.ark.cloud.javacallnative.modules.storage.mapper.WaypointCmdVecThreedMapper;
import com.ark.cloud.javacallnative.modules.storage.service.WaypointCmdService;
import com.ark.cloud.javacallnative.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;

/**
 * @author fukun
 * @create 2021/9/2  下午4:12
 * @description
 */
@Service
public class WaypointCmdServiceImpl implements WaypointCmdService {

    @Autowired
    WaypointCmdMapper waypointCmdDao;
    @Autowired
    Vec3DMapper vec3DDao;
    @Autowired
    WaypointCmdVecThreedMapper waypointCmdVecThreedDao;

    @Override
    public void saveWaypointCmdInfo(WaypointCmd waypointCmd) {
        // 设置UUID
        waypointCmd.setId(UUIDUtil.next());
        System.out.println("waypointCmd:"+waypointCmd);

        // waypoint_cmd表插入
        waypointCmdDao.insert(waypointCmd);

        Long waypointCmdId = waypointCmd.getId();

        // waypoint_cmd_vec_threed、vec_threed表插入
        ArrayList<Vec3D> posList = waypointCmd.getPosList();
        for (Vec3D vec3D : posList) {

            vec3D.setId(UUIDUtil.next());
            vec3DDao.insert(vec3D);

            Long vec3DId = vec3D.getId();

            WaypointCmdVecThreed waypointCmdVecThreed = new WaypointCmdVecThreed();

            waypointCmdVecThreed.setId(UUIDUtil.next());
            waypointCmdVecThreed.setWaypointCmdId(waypointCmdId);
            waypointCmdVecThreed.setVecThreedId(vec3DId);

            waypointCmdVecThreedDao.insert(waypointCmdVecThreed);


        }
    }
}
